package org.giovanolli.mumi.controller.business;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.giovanolli.mumi.controller.AbstractModel;
import org.giovanolli.mumi.entities.Address;
import org.giovanolli.mumi.entities.City;
import org.giovanolli.mumi.entities.DocumentType;
import org.giovanolli.mumi.entities.Patient;
import org.giovanolli.mumi.entities.PatientPrepaid;
import org.giovanolli.mumi.entities.Phone;
import org.giovanolli.mumi.entities.Prepaid;
import org.giovanolli.mumi.entities.Specialist;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

/**
 * The Class PatientModel.
 */
@Controller("patientModel")
@Scope(value = "flow", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class PatientModel extends AbstractModel<Patient> implements Cloneable {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -4295644867846932499L;

	/** The sort property. */
	private String sortProperty;

	/** The first name. */
	private String firstName;

	/** The last name. */
	private String lastName;

	/** The birth date. */
	private Date birthDate;

	/** The document type. */
	private DocumentType documentType;

	/** The selectable document types. */
	private List<DocumentType> selectableDocumentTypes;

	/** The document number. */
	private String documentNumber;

	/** The address. */
	private Address address;

	/** The selectable cities. */
	private List<City> selectableCities;

	/** The edited phone. */
	private Phone editedPhone;

	/** The edited patient prepaid. */
	private PatientPrepaid editedPatientPrepaid;

	/** The selectable prepaids. */
	private List<Prepaid> selectablePrepaids;

	/** The specialist. */
	private Specialist specialist;

	/** The selectable specialists. */
	private List<Specialist> selectableSpecialists;

	/**
	 * Instantiates a new patient model.
	 */
	public PatientModel() {
		editedPhone = new Phone();
		editedPatientPrepaid = new PatientPrepaid();
	}

	/**
	 * Generate printable prepaids.
	 * 
	 * @param list
	 *            the list
	 * @return the string
	 */
	public String generatePrintablePrepaids(List<PatientPrepaid> list) {
		StringBuilder sb = new StringBuilder();
		if (list != null && list.size() == 0) {
			sb.append("NO TIENE");
		} else {
			for (PatientPrepaid prepaid : list) {
				if (prepaid.getPrepaid() != null) {
					sb.append(prepaid.getPrepaid().getName());
				}
				sb.append("(");
				sb.append(prepaid.getAssociateNumber());
				sb.append(") ");
			}
		}
		return sb.toString();
	}

	/**
	 * Gets the address.
	 * 
	 * @return the address
	 */
	public Address getAddress() {
		return address;
	}

	/**
	 * Gets the birth date.
	 * 
	 * @return the birth date
	 */
	public Date getBirthDate() {
		return birthDate;
	}

	/**
	 * Gets the document number.
	 * 
	 * @return the document number
	 */
	public String getDocumentNumber() {
		return documentNumber;
	}

	/**
	 * Gets the document type.
	 * 
	 * @return the document type
	 */
	public DocumentType getDocumentType() {
		return documentType;
	}

	/**
	 * Gets the edited patient prepaid.
	 * 
	 * @return the edited patient prepaid
	 */
	public PatientPrepaid getEditedPatientPrepaid() {
		return editedPatientPrepaid;
	}

	/**
	 * Gets the edited phone.
	 * 
	 * @return the edited phone
	 */
	public Phone getEditedPhone() {
		return editedPhone;
	}

	/**
	 * Gets the first name.
	 * 
	 * @return the first name
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Gets the last name.
	 * 
	 * @return the last name
	 */
	public String getLastName() {
		return lastName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.giovanolli.mumi.controller.AbstractModel#getPageNumber()
	 */
	public Integer getPageNumber() {
		return pageNumber;
	}

	/**
	 * Gets the selectable cities.
	 * 
	 * @return the selectable cities
	 */
	public List<City> getSelectableCities() {
		return selectableCities;
	}

	/**
	 * Gets the selectable document types.
	 * 
	 * @return the selectable document types
	 */
	public List<DocumentType> getSelectableDocumentTypes() {
		if (selectableDocumentTypes == null) {
			setSelectableDocumentTypes(Arrays.asList(DocumentType.values()));
		}
		return selectableDocumentTypes;
	}

	/**
	 * Gets the selectable prepaids.
	 * 
	 * @return the selectable prepaids
	 */
	public List<Prepaid> getSelectablePrepaids() {
		return selectablePrepaids;
	}

	/**
	 * Gets the selectable specialists.
	 * 
	 * @return the selectable specialists
	 */
	public List<Specialist> getSelectableSpecialists() {
		return selectableSpecialists;
	}

	/**
	 * Gets the sort property.
	 * 
	 * @return the sort property
	 */
	public String getSortProperty() {
		return sortProperty;
	}

	/**
	 * Gets the specialist.
	 * 
	 * @return the specialist
	 */
	public Specialist getSpecialist() {
		return specialist;
	}

	/**
	 * Sets the address.
	 * 
	 * @param address
	 *            the new address
	 */
	public void setAddress(Address address) {
		this.address = address;
	}

	/**
	 * Sets the birth date.
	 * 
	 * @param birthDate
	 *            the new birth date
	 */
	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	/**
	 * Sets the document number.
	 * 
	 * @param documentNumber
	 *            the new document number
	 */
	public void setDocumentNumber(String documentNumber) {
		this.documentNumber = documentNumber;
	}

	/**
	 * Sets the document type.
	 * 
	 * @param documentType
	 *            the new document type
	 */
	public void setDocumentType(DocumentType documentType) {
		this.documentType = documentType;
	}

	/**
	 * Sets the edited patient prepaid.
	 * 
	 * @param editedPatientPrepaid
	 *            the new edited patient prepaid
	 */
	public void setEditedPatientPrepaid(PatientPrepaid editedPatientPrepaid) {
		this.editedPatientPrepaid = editedPatientPrepaid;
	}

	/**
	 * Sets the edited phone.
	 * 
	 * @param editedPhone
	 *            the new edited phone
	 */
	public void setEditedPhone(Phone editedPhone) {
		this.editedPhone = editedPhone;
	}

	/**
	 * Sets the first name.
	 * 
	 * @param firstName
	 *            the new first name
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * Sets the last name.
	 * 
	 * @param lastName
	 *            the new last name
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.giovanolli.mumi.controller.AbstractModel#setPageNumber(java.lang. Integer)
	 */
	public void setPageNumber(Integer pageNumber) {
		this.pageNumber = pageNumber;
	}

	/**
	 * Sets the selectable cities.
	 * 
	 * @param selectableCities
	 *            the new selectable cities
	 */
	public void setSelectableCities(List<City> selectableCities) {
		this.selectableCities = selectableCities;
	}

	/**
	 * Sets the selectable document types.
	 * 
	 * @param selectableDocumentTypes
	 *            the new selectable document types
	 */
	public void setSelectableDocumentTypes(List<DocumentType> selectableDocumentTypes) {
		this.selectableDocumentTypes = selectableDocumentTypes;
	}

	/**
	 * Sets the selectable prepaids.
	 * 
	 * @param selectablePrepaids
	 *            the new selectable prepaids
	 */
	public void setSelectablePrepaids(List<Prepaid> selectablePrepaids) {
		this.selectablePrepaids = selectablePrepaids;
	}

	/**
	 * Sets the selectable specialists.
	 * 
	 * @param selectableSpecialists
	 *            the new selectable specialists
	 */
	public void setSelectableSpecialists(List<Specialist> selectableSpecialists) {
		this.selectableSpecialists = selectableSpecialists;
	}

	/**
	 * Sets the sort property.
	 * 
	 * @param sortProperty
	 *            the new sort property
	 */
	public void setSortProperty(String sortProperty) {
		this.sortProperty = sortProperty;
	}

	/**
	 * Sets the specialist.
	 * 
	 * @param specialist
	 *            the new specialist
	 */
	public void setSpecialist(Specialist specialist) {
		this.specialist = specialist;
	}

}
